<html>
<head>
<meta charset="UTF-8">
<title>调度运行监控</title>
	<link id="easyuiTheme" href="../../static/easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css"/>
	<link href="../../static/easyui/themes/icon.css" rel="stylesheet" type="text/css"/>
	<script src="../../static/easyui/jquery.min.js" type="text/javascript"></script>
	<script src="../../static/easyui/jquery.cookie.js" type="text/javascript"></script>
	<script src="../../static/easyui/ui-theme.js" type="text/javascript"></script>
	<script src="../../static/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../static/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.util.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.jquery.ajax.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.easyui.util.js" type="text/javascript"></script>
	<script src="../../ffres/dict/all.js" type="text/javascript"></script>
	<link href="../../static/easyui/themes/frameless.css" rel="stylesheet" type="text/css"/>
	<a href="" target="_blank" id="commonLink" name="commonLink"></a>
<script type="text/javascript">

    $(function() {
        menuFuncOp($.getUrlParam('funcOpStr'));
    });

    //根据用户拥有的资源操作权限信息，动态控制按钮
    function menuFuncOp(funcOpStr) {
        if(null != funcOpStr && "" != funcOpStr){
            var linkButtons = document.getElementById("tb").getElementsByClassName("easyui-linkbutton");
            for(var i = 0; i < linkButtons.length; i++){
                if(funcOpStr.indexOf(linkButtons[i].id) == -1){
                    document.getElementById(linkButtons[i].id).style.display = 'none';
                }
            }
        }
    }
    
	function doAdd() {
		JLEUtil.createModalWin('新增', 'SAgentInfoAdd.html');
	}

	function doUpdate() {
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			JLEUtil.createModalWin('修改', 'SAgentInfoUpdate.html?' + 'agentId='
					+ row.agentId);
		} else {
			$.messager.alert('提示', '请选择一条记录！', 'info');
		}
	}

	function doDelete() {
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			$.messager.confirm('删除提示', '你确定要删除这条记录?', function(r) {
				if (r) {
					var jsonData = JSON.parse('{' + '"agentId":"' + row.agentId
							+ '"' + '}');
					$.restfulDelete('../../api/s/agent/info', jsonData,
							function(data) {
								$.messager.alert('提示', '记录删除成功!', 'info');
								$('#dg').datagrid('reload');
							});
				}
			});
		} else {
			$.messager.alert('提示', '请选择一条记录！', 'info');
		}
	}

	function doView() {
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			JLEUtil.createModalWin('详情', 'SAgentInfoView.html?' + '&agentId='
					+ row.agentId);
		} else {
			$.messager.alert('提示', '请选择一条记录！', 'info');
		}
	}    

	function doActiveAgent(){
		//JLEUtil.createModalWin('新增', 'SAgentInfoAdd.html');
		var row = $('#dg').datagrid('getSelected');
		if (row){
			$.messager.confirm('提示', '是否确定要激活该执行节点?', function(r){
				if(r) {
					$.restfulGet('../../api/s/srvs/cron/active/' + row.agentId, null, function(data){
						if(data.code == '0') {
							$.messager.alert('提示', data.message,'success');
						} else {
							$.messager.alert('提示', data.message,'error');
						}
					});
					$('#dg').datagrid('reload');
				}
			});
		} else {
			$.messager.alert('提示','请选择一条记录！','info');
		}
	}
	
	function doStopAgent() {
		var row = $('#dg').datagrid('getSelected');
		if (row){
			$.messager.confirm('提示', '是否确定要停止该执行节点?', function(r){
				if(r) {
					$.restfulGet('../../api/s/srvs/cron/stop/' + row.agentId, null, function(data){
						if(data.code == '0') {
							$.messager.alert('提示', data.message,'success');
						} else {
							$.messager.alert('提示', data.message,'error');
						}
					});
					$('#dg').datagrid('reload');
				}
			});
			//JLEUtil.createModalWin('修改', 'SAgentInfoUpdate.html?' + 'agentId=' + row.agentId);
		} else {
			$.messager.alert('提示','请选择一条记录！','info');
		}
	}

	function doMonitorAgent(){
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			JLUtil.linkNewPage("SSrvsCronConfList.html?agentId=" + row.agentId);
		} else {
			$.messager.alert('提示','请选择一条记录！','info');
		}
	}	

	function reloadList(){
		$('#dg').datagrid('reload');
		JLEUtil.closewin();
	};	
</script>
</head>
<body class="easyui-layout">
<div data-options="region:'north',title:''" style="height: 40px;">
	<form id="searchForm">
		<table>
			<tr>
				<td>&nbsp;执行节点标识：</td>
				<td><input name="agentId" id="agentId"/></td>
				<td><a class="easyui-linkbutton" href="javascript:void(0);" onclick="JLEUtil.queryForm('searchForm','dg','../../api/s/agent/infos');">查找</a></td>
				<td><a class="easyui-linkbutton" href="javascript:void(0);" onclick="JLEUtil.clearForm('searchForm');">清空</a></td>
			</tr>
		</table>
	</form>
</div>
<div data-options="region:'center',split:false">
<table id="dg" class="easyui-datagrid" title="" style="width:100%;height:98%"
			data-options="singleSelect:true,collapsible:true,url:'../../api/s/agent/infos',method:'post'"
			toolbar="#tb"
		title="Load Data" 
		rownumbers="true" pagination="true" pageSize="20">
		<thead>
			<tr>
				<th data-options="field:'agentId',resizable:true" >执行节点标识</th>
				<th data-options="field:'agentName',resizable:true" >执行节点名称</th>
				<th data-options="field:'agentState',resizable:true" formatter="formatter_INST_STATE">执行节点状态</th>
				<th data-options="field:'agentUrl',resizable:true" >执行节点地址</th>
				<th data-options="field:'startTime',resizable:true" >启动时间</th>
				<th data-options="field:'stopTime',resizable:true" >停止时间</th>
			</tr>
		</thead>
	</table>
</div>
<div id="tb" style="padding:1px">
	<div style="margin-bottom:2px">
		<a href="javascript:doAdd()" class="easyui-linkbutton" iconCls="icon-add" plain="true" id="create">新增</a>
		<a href="javascript:doUpdate()" class="easyui-linkbutton" iconCls="icon-edit" plain="true" id="modify">修改</a>
		<a href="javascript:doDelete()" class="easyui-linkbutton" iconCls="icon-remove" plain="true" id="delete">删除</a>
		<a href="javascript:doView()" class="easyui-linkbutton" iconCls="icon-ok" plain="true" id="detail">查看</a>	
		<a href="javascript:doActiveAgent()" class="easyui-linkbutton" iconCls="icon-add" plain="true" id="start">激活</a>
		<a href="javascript:doStopAgent()" class="easyui-linkbutton" iconCls="icon-edit" plain="true" id="stop">停止</a>
		<a href="javascript:doMonitorAgent()" class="easyui-linkbutton" iconCls="icon-ok" plain="true" id="ctrl">监控</a>
	</div>
</div>
</body>
</html>
